home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / CW Examples / lib / nshc_utl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-17  |  2.1 KB  |  110 lines  |  [TEXT/KAHL]

  1. /* ========================================
  2.  
  3.     nshc_utl.c
  4.     
  5.     Copyright (c) 1993,1994 Newport Software Development
  6.     
  7.     You may distribute unmodified copies of this file for
  8.     noncommercial purposes.  You may use this file as a
  9.     reference when writing your own nShell(tm) commands.
  10.     
  11.     All other rights are reserved.
  12.     
  13.    ======================================== */
  14.    
  15. #include "nshc.h"
  16.                     
  17. #include "nshc_utl.proto.h"
  18.  
  19. // ===== version tracking ======
  20.                 
  21. int nshc_bad_version(t_nshc_parms *nshc_parms, t_nshc_calls *nshc_calls, int version)
  22. {
  23.     if ( nshc_parms->version != version ) {
  24.         nshc_calls->NSH_putStr_err("\pThis command is not of a compatible version.\r");
  25.         nshc_parms->result = NSHC_ERR_VERSION;
  26.         nshc_parms->action = nsh_idle;
  27.         return(1);
  28.         }
  29.     else
  30.         return(0);
  31. }
  32.  
  33. // ===== option exploration routines =====
  34.  
  35. int nshc_got_option(t_nshc_parms *nshc_parms, char option)
  36. {
  37.     char    c;
  38.     int        pos;
  39.     int        arg;
  40.     int     found;
  41.     int        bad_format;
  42.     
  43.     arg = 1;
  44.     found = 0;
  45.     
  46.     while (!found && (arg < nshc_parms->argc)) {
  47.         pos = nshc_parms->argv[arg];
  48.         if ( nshc_parms->arg_buf[pos++] == '-' ) {
  49.             bad_format = 0;
  50.             while (c = nshc_parms->arg_buf[pos++]) {
  51.                 if (c == option) found = arg;
  52.                 if ( ((( c < 'a' ) || ( c > 'z' )) && (( c < 'A' ) || ( c > 'Z' ))) )
  53.                     bad_format = 1;
  54.                 }
  55.             }
  56.         if (bad_format)
  57.             found = 0;
  58.         arg++;
  59.         }
  60.         
  61.     return( found );
  62. }
  63.  
  64. int nshc_is_numeric_operand(t_nshc_parms *nshc_parms, int arg)
  65. {
  66.     int        good;
  67.     int        pos;
  68.     char    c;
  69.     
  70.     good = 1;
  71.     pos = nshc_parms->argv[arg];
  72.     
  73.     if (nshc_parms->arg_buf[pos] == '-') pos++;
  74.         
  75.     while( good && (c = nshc_parms->arg_buf[pos++]) )
  76.         if ((c < '0') || (c > '9'))
  77.             good = 0;
  78.     
  79.     return( good );
  80. }
  81.  
  82. int nshc_is_operand(t_nshc_parms *nshc_parms, int arg)
  83. {
  84.     int        pos;
  85.     char    c;
  86.     
  87.     pos = nshc_parms->argv[arg];
  88.     
  89.     c = nshc_parms->arg_buf[pos++];
  90.     
  91.     return( c != '-' );
  92. }
  93.  
  94. int nshc_next_operand(t_nshc_parms *nshc_parms, int start)
  95. {
  96.     int found;
  97.     int arg;
  98.     
  99.     arg = start + 1;
  100.     found = 0;
  101.     
  102.     while (!found && ( arg < nshc_parms->argc )) {
  103.         if (nshc_is_operand( nshc_parms, arg ))
  104.             found = arg;
  105.         arg++;
  106.         }
  107.         
  108.     return( found );
  109. }
  110.